package cn.javaxc.mvcwork.util.common;
import cn.javaxc.mvcwork.modules.file.*;
import cn.javaxc.mvcwork.controller.MVCConfig;
import cn.javaxc.mvcwork.util.common.*;
import java.net.URL;
import java.util.*;
import javax.activation.*;
import javax.mail.*;
import javax.mail.internet.*;


public class SMTPHelper 
{ 
  protected String host = "";
  protected String from = "";
  protected ArrayList to = new ArrayList();
  protected ArrayList cc = new ArrayList();
  protected ArrayList bcc = new ArrayList();
  protected String subject = "";
  protected String body = "";
  protected String type = "text";
  protected Exception errorMsg = null;
  protected HashMap replyTo = new HashMap();
  protected FileItemList attachments = null;
  protected ArrayList byteArrayAttachments = null;
  protected HashMap images = new HashMap();
  protected String mailTable;
  protected String mailFileId;

  


  
  public void setHost(String tmp) {
    host = tmp;
  }


  
  public void setFrom(String tmp) {
    from = tmp;
  }


  
  public void setTo(String tmp) {
    to.clear();
    if (tmp.indexOf(",") > -1) {
      addMultiple(to, tmp);
    } else {
      addTo(tmp);
    }
  }


  
  public void setCc(String tmp) {
    cc.clear();
    if (tmp.indexOf(",") > -1) {
      addMultiple(cc, tmp);
    } else {
      addCc(tmp);
    }
  }


  
  public void setBcc(String tmp) {
    bcc.clear();
    if (tmp.indexOf(",") > -1) {
      addMultiple(bcc, tmp);
    } else {
      addBcc(tmp);
    }
  }


  
  public void setSubject(String tmp) {
    subject = tmp;
  }


  
  public void setBody(String tmp) {
    body = tmp;
  }


  
  public HashMap getReplyTo() {
    return replyTo;
  }


  
  public void setReplyTo(HashMap replyTo) {
    this.replyTo = replyTo;
  }


  
  public void setAttachments(FileItemList tmp) {
    this.attachments = tmp;
  }


  
  public void setType(String tmp) {
    type = tmp;
  }

  public String getSubject() {
    return subject;
  }

  public String getBody() {
    return body;
  }

  
  public Exception getErrorMsg() {
    return errorMsg;
  }


  
  public void addTo(String tmp) {
    to.add(tmp);
  }


  
  public void addReplyTo(String address) {
    replyTo.put(address, "");
  }


  
  public void addReplyTo(String address, String personal) {
    replyTo.put(address, personal);
  }


  
  public void addCc(String tmp) {
    cc.add(tmp);
  }


  
  public void addBcc(String tmp) {
    bcc.add(tmp);
  }

  
  private void addMultiple(ArrayList list, String emails) {
    StringTokenizer st = new StringTokenizer(emails, ",");
    while (st.hasMoreTokens()) {
      String email = st.nextToken();
      list.add(email.trim());
    }
  }	
  public String getMailTo(){
	return MVCConfig.getConfig().getClassProperty(this.getClass(),"mailto");
  }
  public int send() {
	  return send(MVCConfig.getConfig().getClassCfg(this.getClass()));
  }
  public int send(Map user_email) {
	  throw new UnsupportedOperationException();
  }
}
